package com.study.notepad.util;

import org.apache.commons.lang3.StringUtils;

public class PageUtil {

    public final static int PAGE_SIZE = 10;
    public final static int PAGE_NUM = 1;
    private int total;                          //记录总数
    private int pageSize = PAGE_SIZE;              //每页的最大记录数
    private int totalPage;                      //总页数
    private int startItems;                     //开始的记录数
    private int pageNum = PAGE_NUM;                //当前页码

    private Object data;

    public PageUtil(String pageSizeStr, String pageNumStr) {
        if (StringUtils.isNotBlank(pageSizeStr)) {
            this.pageSize = Integer.parseInt(pageSizeStr);
        }
        if (StringUtils.isNotBlank(pageNumStr)) {
            this.pageNum = Integer.parseInt(pageNumStr);
        }
        this.startItems = (pageNum - 1) * pageSize;
    }

    public static void main(String[] args) {
        Double ceil = Math.ceil(20 / 1.0 / 10);
        System.out.println(ceil.intValue());
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        Double ceil = Math.ceil(total / 1.0 / pageSize);
        totalPage = ceil.intValue();
        this.total = total;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPage() {

        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getStartItems() {
        return startItems;
    }

    public void setStartItems(int startItems) {
        this.startItems = startItems;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

}
